package com.starmark.common.queue.producer.redis;


import com.starmark.common.queue.producer.api.dto.MessageQueueDto;
import com.starmark.common.queue.producer.api.service.IMessageQueueProducerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * redis 消息队列
 *
 * @author starmark
 * @date 2020/5/1  上午10:41
 */
@Service
public class MessageQueueRedisProducerServiceImpl implements IMessageQueueProducerService {

    @Autowired
    private StringRedisTemplate  redisTemplate;


    @Override
    public boolean produceMessage(MessageQueueDto messageQueueDto) {
        redisTemplate.convertAndSend(messageQueueDto.getTopic(),messageQueueDto.getMessage());
        return true;
    }

    @Override
    public boolean support(String producerType) {
        return Objects.equals(producerType,"redis");
    }
}
